def func(num):
	if len(str(num)) != 4: return 0
	nums = []
	for n in range(4): nums += [int(str(num)[n:n1]) for n1 in range(n + 1, 5) if not findM(int(str(num)[n:n1]))]
	return max(nums) if nums else 0

def findM(num):
	if num == 1: return 0
	for x in range(2, num // 2 + 1): 
		if not num % x and findM(x) == 0: return x
	return 0
print(func(int(input())))
